package com.pms.task;

import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.pms.domain.JobConfig;
import com.pms.service.HdReportService;
import com.pms.service.ReportService;

public class FTPJob implements Job, ApplicationContextAware {

	private static ApplicationContext applicationContext;

	ReportService reportService;
	
	HdReportService hdReportService;

	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		
		JobDataMap jobDataMap = context.getMergedJobDataMap();
		JobConfig cfg = (JobConfig) jobDataMap.get("jobConfig");
		
		Integer parseType = cfg.getParsetype();
		if(1==parseType){
			reportService = (ReportService) applicationContext.getBean("reportService");
			reportService.handler(cfg);
		}else if(2==parseType){
			hdReportService = (HdReportService) applicationContext.getBean("hdReportService");
			hdReportService.hdHandler(cfg);
		}
	}

	@SuppressWarnings("static-access")
	@Override
	public void setApplicationContext(ApplicationContext arg0) throws BeansException {
		this.applicationContext = arg0;
	}
	

}
